/************** init.html **************/

function query_mark(page) {
	var parm = $('#queryForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('markTopic-query');
	sys_record_parm('markTopic',parm);
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#markTopicResultList').html(result);
		}
	});
}
$('#className').keydown(function(event) {
		if(event.keyCode == '13') {
			queryOcClasses_est();
			return false;
		}
});
$('#userName').keydown(function(event) {
	if(event.keyCode == '13') {
		queryStudent_est();
		return false;
	}
});

/**
 * 查询班级
 */
function queryOcClasses_est(){
	var name = $("#className").val();
	var parm = {"name" : name};
	var url = create_url('markTopic-queryClass');
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#classInfoResultList').html(result);
			$('#studentResultList').html("");
			$('#courseResultList').html("");
			$("#studentName").html("");
		}
	});
}

function setClassesCode_est(code,btn){
	$("#classCode").val(code);
	$("#classInfoResultList").find("a").each(function(){
		$(this).removeClass("focus");
	})
	btn.addClass("focus");
	queryStudent_est();
}

function setStudentCode_est(code,name,btn){
	$("#sutdentCode").val(code);
	$("#studentName").html(name)
	$("#studentResultList").find("a").each(function(){
		$(this).removeClass("select m-l-none");
	})
	btn.addClass("select m-l-none");
	queryCourseAndExamRecord_est();
}
/**
 * 查询学生
 */
function queryStudent_est(){
	var name = $("#userName").val();
	var code = $("#classCode").val();
	if(code == "" || code.length == 0 ){
		sys_msg("请先选择班级！");
		return
	}
	var parm = {"code" : code, "name" : name};
	var url = create_url('markTopic-queryStudent');
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#studentResultList').html(result);
			$('#courseResultList').html("");
		}
	});
}


/**
 * 查询查询课程
 */
function queryCourseAndExamRecord_est(){
	var clc = $("#classCode").val();
	var uc = $("#sutdentCode").val();
	var parm = {"clc" : clc, "uc" : uc};
	var url = create_url('markTopic-queryCourse');
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#courseResultList').html(result);
		}
	});
}

/*************************courseList.html**********************************/
function markTopic_est(code){
	var url = create_url("markTopic-markTopicInfo");
	var parm = {"code" : code};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'850px', height:'600px', open:true});
}

function showHideDetailDiv(btn){
	var dis = btn.parent().parent().find(".detailDiv");
	if(dis.is(":visible")){
		dis.hide();
	}else{
		dis.show();
	}
}
/******************************mark.html*******************************************/
/**
 *	控制隐藏和展开课程
 */
function showPageDiv(btn,page){
	$(".showDiv").each(function(){
		$(this).hide();
	})
	$("#tags").find("li").each(function(){
		$(this).removeClass("active");
	})
	btn.parent().addClass("active");
	$("#tagContent"+page).show();
}
/**
 *	防止单击BUTTON跳转
 */
function onclickNull(){}

/**
 *	计算总得分
 */
function calcTotalPoints(){
	var total = 0;
	$(".point").each(function(){
		var point = $(this).val();
		if(point != "" && point.length != 0){
			total = total + parseFloat(point);
		}
	})
	$("#totalPoint").html("本次考试得分：" + total +"分");
	$("#examScore").val(total);
}

/**
 *	验证输入的分数是否正确
 */
function checkPointsGt(btn){
	var old = btn.parent().find(".points").val();
	var now = btn.val();
	var regex = /^[+]?\d*\.?\d*$/;
	if(now.length == 0 || now == ""){
		sys_msg("请输入该题的得分","");
		btn.focus();
		return
	}
	if(!regex.test(now)){
		sys_msg("得分,只能是正整数和正小数","");
		btn.focus();
		return
	}
	if(parseFloat(now) > parseFloat(old)){
		sys_msg("您输入的得分  大于了该题的分值，请重新输入","");
		btn.focus();
		return
	}
	calcTotalPoints();
}

/**
 * 保存阅卷信息
 */
function saveMarkTopic_est(){
	calcTotalPoints();
	var parm = $('#editMarkForm').serialize();
	var url = create_url('markTopic-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				$.fn.colorbox.close();
				query_mark();
			} else {
				sys_msg('操作失败，请刷新后重试');
			}
		}
	});
}

/**
 *验证保存信息是否正确
 */
function checkSaveMarkTopic_est(){
	var regex = /^[+]?\d*\.?\d*$/;
	var flag = false;
	$(".inpupoin").each(function(){
		var point = $(this).val();
		if(point.length == 0 || point == ""){
			sys_msg("请填写该题的得分!","");
			$(this).focus();
			flag = true;
			return false
		}
		if(!regex.test(point)){
			sys_msg("得分,只能填写正整数和正小数!","");
			$(this).focus();
			flag = true;
			return false
		}
	});
	if(!flag){
		saveMarkTopic_est();
	}
}

function selectCourse_markTopic(){
	var url = create_url('markTopic-aidInit');
	$.colorbox({overlayClose:false, href:url, data:null, close:'[关闭]', width:'850px', height:'650px', open:true});
}

function queryCourse_markTopic() {
	sys_loading();
	var parm = $('#queryForm').serialize();
	var url = create_url('markTopic-aidList');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#courseResultList').html(result);
		}
	});
}
function chooseCourse_markTopic(code,name) {
	$('#cc').val(code);
	$('#ccn').val(name);
	$.fn.colorbox.close();
}

function selectClasses_markTopic(){
	var url = create_url('markTopic-aidInit1');
	$.colorbox({overlayClose:false, href:url, data:null, close:'[关闭]', width:'850px', height:'650px', open:true});
}

function queryClasses_markTopic() {
	sys_loading();
	var parm = $('#queryForm').serialize();
	var url = create_url('markTopic-aidList1');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#clcResultList').html(result);
		}
	});
}
function chooseClasses_markTopic(code,name) {
	$('#clc').val(code);
	$('#clcn').val(name);
	$.fn.colorbox.close();
}

function selectUser_markTopic(){
	var url = create_url('markTopic-aidInit2');
	$.colorbox({overlayClose:false, href:url, data:null, close:'[关闭]', width:'850px', height:'650px', open:true});
}

function queryUser_markTopic() {
	sys_loading();
	var parm = $('#queryForm').serialize();
	var url = create_url('markTopic-aidList2');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#userResultList').html(result);
		}
	});
}
function chooseUser_markTopic(code,name) {
	$('#cu').val(code);
	$('#cn').val(name);
	$.fn.colorbox.close();
}